console.log("服务初始化............................");
const express = require('express');
const app = express();
const proxy = require('http-proxy-middleware');
let port = 3000;


const mysql = require('mysql');


function loadConfig() {
    let connection = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'test'
    });
    connection.connect();
    connection.query("select * from config order by `order` ", function (e, rs) {
        for (let row of rs) {
            console.log(row.path + " " + row.target);
            app.use(row.path, proxy({target: row.target, changeOrigin: true}));
        }
        // 其他走公共
        app.use('/', proxy({target: 'https://zm.gaiay.net.cn', changeOrigin: true}));
        app.listen(port);
        console.log('启动完成:' + port)

    });
    connection.end();
}

loadConfig();




